package com.example.cloudstreamdemo.ctrl;

import jakarta.annotation.Resource;
import org.springframework.cloud.stream.function.StreamBridge;
import org.springframework.http.ResponseEntity;
import org.springframework.messaging.Message;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 *  测试
 *
 * @author 吕晓飞
 * @since 2024/1/16 18:18
 * @version 1.0
 */
@RestController
@RequestMapping("/test")
public class TestCtrl {

    @Resource
    private StreamBridge streamBridge;

    @GetMapping("/send")
    public ResponseEntity<String> send(@RequestParam String bizFlag) {
        Message<String> msgData = MessageBuilder//
                .withPayload("{\"name\": \"张三\", \"age\": 18, \"sex\": \"男\"}")//
                // 设置业务标识
                .setHeader("bizFlag", bizFlag)
                .build();
        streamBridge.send("producer-out-0", msgData);
        return ResponseEntity.ok("ok");
    }
}
